/**
 * Created by apple on 2016/11/16.
 */

module.exports = function(sequelize, DataTypes) {
    var Area = sequelize.define('crm_area', {
        area_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            unique: true,
            primaryKey: true,
            autoIncrement: true
        },
        parent_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 0
        },
        area_name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        area_type: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 2
        }
    }, {
        underscore: true,
        'timestamps': false,
        'createdAt': false,
        'updatedAt': false,
        freezeTableName: true, // 数据库表名不增加复数
    }, {
        classMethods: {
            associate: function(models) {
                Area.hasMany(models.Hospital);
            }
        }
    });

    return Area;
};